package Application.MapApplication.view.ui
{
	import Application.MapApplication.view.ViewBaseMed;
	
	import Application.MapApplication.def.Def;
	import def.XG;
	import Application.MapApplication.def.Manager;
	
	import flash.display.Sprite;
	
	import org.puremvc.as3.interfaces.INotification;
	import org.puremvc.as3.patterns.mediator.Mediator;

	public class UIBaseMed extends ViewBaseMed
	{
		public var alignGroup : Array = [];
		public var offX : int;
		public var offY : int;
		
		private var _stageWidth : int;
		private var _stageHeight : int;
		
		public function UIBaseMed(mediatorName : String,alignGroup : Array)
		{	
			super(mediatorName);
			
			this.alignGroup = alignGroup;
			
			StageSizeChanged();
		}
		
		override public function listNotificationInterests() : Array
		{
			return [Def.STAGE_SIZE_CHANGED];
		}
		
		override public function handleNotification(notification:INotification):void
		{
			switch(notification.getName())
			{
				case Def.STAGE_SIZE_CHANGED:
					StageSizeChanged();
					break;
				default :
					break;
			}
		}
		
		private function StageSizeChanged() : void
		{
			if(_stageWidth == XG.stage.stageWidth && _stageHeight == XG.stage.stageHeight) return;
			
			_stageWidth = XG.stage.stageWidth;
			_stageHeight = XG.stage.stageHeight;
				
			for each(var align : String in alignGroup)
			{
				switch(align)
				{
					case Def.STAGE_ALIGN_TOP:
						viewComponent.y=0;
						break;
					case Def.STAGE_ALIGN_BOTTOM:
						viewComponent.y=XG.stage.stageHeight - viewComponent["Pan_Layer"].height;
						break;
					case Def.STAGE_ALIGN_LEFT:
						viewComponent.x=0;
						break;
					case Def.STAGE_ALIGN_RIGHT:
						viewComponent.x=XG.stage.stageWidth - viewComponent["Pan_Layer"].width;
						break;
					case Def.STAGE_ALIGN_MIDDLEY:
						viewComponent.y=XG.stage.stageHeight/2-viewComponent["Pan_Layer"].height/2;
						break;
					case Def.STAGE_ALIGN_MIDDLEX:
						viewComponent.x=XG.stage.stageWidth/2-viewComponent["Pan_Layer"].width/2;
						break;
					case Def.STAGE_ALIGN_MIDDLE:
						viewComponent.x=XG.stage.stageWidth/2-viewComponent["Pan_Layer"].width/2;
						viewComponent.y=XG.stage.stageHeight/2-viewComponent["Pan_Layer"].height/2;
						break;
					default : 
						break;
				}
			}
			setOffset();
		}
		
		private function setOffset() : void
		{
			viewComponent.x+=offX;
			viewComponent.y+=offY;
		}
	}
}